package com.shtel.custbehavior.controller;

import com.shtel.custbehavior.entity.*;
import com.shtel.custbehavior.mapper.QueryMapper;
import com.shtel.custbehavior.service.CustbehaviorService;
import com.shtel.custbehavior.util.Cors;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description = "行为信息服务接口")
@RestController
public class CustbehaviorController extends Cors {

    @Autowired
    CustbehaviorService custbehaviorService;
    @Autowired
    QueryMapper queryMapper;

    @GetMapping("test")
    public String test(){

        return "testtesttest";
    }

    //查询投诉信息
    @ApiOperation(value = "查询投诉信息", notes = "查询投诉信息")
    @GetMapping("querytousuinfo/{creditnum}")
    public List<TousuInfo> querytousuinfo(@PathVariable String creditnum) {

        return custbehaviorService.querytousuinfo(creditnum);
    }

    //查询感知信息
    @ApiOperation(value = "查询感知信息", notes = "查询感知信息")
    @GetMapping("queryfeelinfo/{creditnum}")
    public List<FeelInfo> queryfeelinfo(@PathVariable String creditnum) {

        return custbehaviorService.queryfeelinfo(creditnum);

    }

    //查询接触轨迹
    @ApiOperation(value = "查询接触轨迹", notes = "查询接触轨迹")
    @GetMapping("querycontactinfo/{creditnum}")
    public List<ContactInfo> querycontactinfo(@PathVariable String creditnum) {
        return custbehaviorService.querycontactinfo(creditnum);
    }

    //查询服务信息
    @ApiOperation(value = "查询服务信息", notes = "查询服务信息")
    @GetMapping("queryserviceinfo/{creditnum}")
    public List<ServiceInfo> queryserviceinfo(@PathVariable String creditnum) {
        return custbehaviorService.queryserviceinfo(creditnum);
    }

    //查询营销标签和推荐
    @ApiOperation(value = "查询营销标签和推荐", notes = "查询营销标签和推荐")
    @GetMapping("querycustlabel/{creditnum}")
    public List<LabelAndRecommend> querycustlabel(@PathVariable String creditnum) {
        return custbehaviorService.querycustlabel(creditnum);
    }

    //营业员登录
    @ApiOperation(value = "营业员登录", notes = "营业员登录")
    @GetMapping("login/{username}/{password}")
    public Map<String,String> login(@PathVariable String username,@PathVariable String password){


        Integer result = queryMapper.login(username,password);
        Map<String,String> resultmap= new HashMap<>();
        if(result==null){
            resultmap.put("code","400");
            resultmap.put("msg","用户名或密码错误");

            return resultmap;
        }

        if(result>0){
            resultmap.put("code","200");
            resultmap.put("msg","登录成功");
            return resultmap;

        }
        resultmap.put("code","500");
        resultmap.put("msg","登录失败");
        return resultmap;
    }
}
